<?php
/******************************
 * EQdkp
 * Copyright 2002-2003
 * Licensed under the GNU GPL.  See COPYING for full terms.
 * ------------------
 * listitemrequest.php
 * Began: November 2007
 * 
 * 
 ******************************/
 
define('EQDKP_INC', true);
define('IN_ADMIN', true);
$eqdkp_root_path = './../';
include_once($eqdkp_root_path . 'common.php');

$user->check_auth('a_item_');

$sort_order = array(
    0 => array('item_name', 'item_name desc'),
    1 => array('item_level', 'item_level desc'),
    2 => array('item_jobs', 'item_jobs desc'),
    3 => array('dropped_from', 'dropped_from desc')
);

$current_order = switch_order($sort_order);

$total_items = $db->query_first('SELECT count(DISTINCT item_name) FROM ' . ITEM_DATA_TABLE);
$start = ( isset($_GET['start']) ) ? $_GET['start'] : 0;

$sql = 'SELECT item_data_id, item_name, item_level, item_jobs, dropped_from 
        FROM ' . ITEM_DATA_TABLE . '
        ORDER BY '.$current_order['sql']. '
        LIMIT '.$start.','.$user->data['user_ilimit'];

$listitems_footcount = sprintf($user->lang['listpurchased_footcount'], $total_items, $user->data['user_ilimit']);
$pagination = generate_pagination('listitemdata.php'.$SID.'&amp;o='.$current_order['uri']['current'], $total_items, $user->data['user_ilimit'], $start);

if ( !($items_result = $db->query($sql)) )
{
    message_die('Could not obtain item data information', 'Database error', __FILE__, __LINE__, $sql);
}

while ( $item = $db->fetch_record($items_result) )
{
    $tpl->assign_block_vars('items_row', array(
        'ROW_CLASS' => $eqdkp->switch_row_class(),
        'NAME'      => stripslashes($item['item_name']),
        'CLASS'     => ( !empty($item['item_jobs']) ) ? $item['item_jobs'] : '',
        'LEVEL'     => ( !empty($item['item_level']) ) ? $item['item_level'] : '',
        'DROPPED_FROM'  => ( !empty($item['dropped_from']) ) ? $item['dropped_from'] : '',
        'U_VIEW_ITEM' => 'additemdata.php'.$SID.'&amp;' . URI_ITEM . '='.$item['item_data_id'])
    );
}
$db->free_result($items_result);

$tpl->assign_vars(array(
    'L_ITEM' => $user->lang['item'],
    'L_LEVEL' => $user->lang['level'],
    'L_CLASS' => $user->lang['class'],
    'L_DROPPED_FROM' => $user->lang['dropped_from'],

    'O_ITEM_CLASS' => $current_order['uri'][2],
    'O_ITEM_DROPPED_FROM' => $current_order['uri'][3],
    'O_ITEM_LEVEL' => $current_order['uri'][1],
    'O_NAME' => $current_order['uri'][0],

    'U_LIST_ITEMS' => 'listitemdata.php'.$SID.'&amp;',

    'START' => $start,
    'LISTITEMS_FOOTCOUNT' => $listitems_footcount,
    'ITEM_PAGINATION' => $pagination)
);

$eqdkp->set_vars(array(
    'page_title'    => sprintf($user->lang['admin_title_prefix'], $eqdkp->config['guildtag'], $eqdkp->config['dkp_name']).': '.$user->lang['listitemdata_title'],
    'template_file' => 'listitemdata.html',
    'display'       => true)
);
?>
